import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import Login from '../views/logins.vue'

// import ddd from '../views/ddd.vue'


Vue.use(VueRouter)

const routes = [{
        path: '/',
        name: 'login',
        component: Login

    },

    {
        path: '/loginfree', //免登陆
        name: 'loginfree',
        component: () =>
            import('../views/loginfree.vue')
    },
    {
        path: '/loginHttps', //免登陆
        name: 'loginHttps',
        component: () =>
            import('../views/loginHttps.vue')
    },
    {
        path: '/pressDataMonitor', //免登陆
        name: 'pressDataMonitor',
        component: () =>
            import('../views/networkTestMachines/pressDataMonitor/index.vue')
    },
    // 
    {
        path: '/home',
        name: 'Home',
        component: Home,
        // redirect: "/aaa",
        children: [
            // 
            {
                path: '/codeGenerator', //代码生成器
                name: 'codeGenerator',
                component: () =>
                    import('../views/SysManage/minjManage/codeGenerator.vue')
            },
            {
                path: '/index', //试验检测依据管理-----查看
                name: 'index',
                component: () =>
                    import('../views/index.vue')
            },

            // 试验机管理
            { // 版本管理
                path: '/versionManage',
                name: 'versionManage',
                component: () =>
                    import('../views/testMachineManage/versionManage/index.vue'),
                meta: {
                    requiresAuth: true
                },
            },
            { // 试验名称
                path: '/testNameManage',
                name: 'testNameManage',
                component: () =>
                    import('../views/testMachineManage/testNameManage/index.vue'),
                meta: {
                    requiresAuth: true
                },
            },
            { // 设备管理
                path: '/equipmentManage',
                name: 'equipmentManage',
                component: () =>
                    import('../views/testMachineManage/equipmentManage/index.vue'),
                meta: {
                    requiresAuth: true
                },
            },
            // 试验机管理
            //    异常数据处理
            { // 数据处理
                path: '/abnormalDataProcess',
                name: 'abnormalDataProcess',
                component: () =>
                    import('../views/abnormalDataProcessManage/abnormalDataProcess/index.vue'),
                meta: {
                    requiresAuth: true
                },
            },
            //    异常数据处理





            // 试验机联网


            { // 试验数据监控之沥青设备监控--针入度
                path: '/penetrationMonitor',
                name: 'penetrationMonitor',
                component: () =>
                    import('../views/machineNetworkManage/testDataMonitorManage/asphaltEquipmentMonitor/penetrationMonitor/index.vue'),
                meta: {
                    requiresAuth: true
                },
            },
            { // 试验数据监控之沥青设备监控--软化点
                path: '/softenPointMonitor',
                name: 'softenPointMonitor',
                component: () =>
                    import('../views/machineNetworkManage/testDataMonitorManage/asphaltEquipmentMonitor/penetrationMonitor/index.vue'),
                meta: {
                    requiresAuth: true
                },
            },
            { // 试验数据监控之沥青设备监控--延度
                path: '/ductilityMonitor',
                name: 'ductilityMonitor',
                component: () =>
                    import('../views/machineNetworkManage/testDataMonitorManage/asphaltEquipmentMonitor/ductilityMonitor/index.vue'),
                meta: {
                    requiresAuth: true
                },
            },
            { // 试验数据监控之沥青混合料监控--稳定度
                path: '/stabilityMonitor',
                name: 'stabilityMonitor',
                component: () =>
                    import('../views/machineNetworkManage/testDataMonitorManage/asphaltMixtureMonitor/stabilityMonitor/index.vue'),
                meta: {
                    requiresAuth: true
                },
            },
            { // 试验数据监控之沥青混合料监控--沥青含量
                path: '/asphaltContentMonitor',
                name: 'asphaltContentMonitor',
                component: () =>
                    import('../views/machineNetworkManage/testDataMonitorManage/asphaltMixtureMonitor/asphaltContentMonitor/index.vue'),
                meta: {
                    requiresAuth: true
                },
            },
            { // 试验数据监控之沥青混合料监控--车辙
                path: '/rutMonitor',
                name: 'rutMonitor',
                component: () =>
                    import('../views/machineNetworkManage/testDataMonitorManage/asphaltMixtureMonitor/rutMonitor/index.vue'),
                meta: {
                    requiresAuth: true
                },
            },

            { // 试验数据处理之压力机数据处理
                path: '/pressDataProcess',
                name: 'pressDataProcess',
                component: () =>
                    import('../views/machineNetworkManage/testDataProcessManage/pressDataProcess/index.vue'),
                meta: {
                    requiresAuth: true
                },
            },
            { // 试验数据处理之万能机数据处理
                path: '/zigzagDataProcess',
                name: 'zigzagDataProcess',
                component: () =>
                    import('../views/machineNetworkManage/testDataProcessManage/zigzagDataProcess/index.vue'),
                meta: {
                    requiresAuth: true
                },
            },

            { // 试验数据处理之不合格数据处理记录
                path: '/dataProcessRecords',
                name: 'dataProcessRecords',
                component: () =>
                    import('../views/machineNetworkManage/testDataProcessManage/dataProcessRecords/index.vue'),
                meta: {
                    requiresAuth: true
                },
            },
            { // 试验数据处理之抗折抗压机数据处理
                path: '/compressivePressDataProcess',
                name: 'compressivePressDataProcess',
                component: () =>
                    import('../views/machineNetworkManage/testDataProcessManage/compressivePressDataProcess/index.vue'),
                meta: {
                    requiresAuth: true
                },
            },
            { // 试验数据处理之沥青设备处理--针入度
                path: '/penetrationProcess',
                name: 'penetrationProcess',
                component: () =>
                    import('../views/machineNetworkManage/testDataProcessManage/asphaltEquipmentProcess/penetrationProcess/index.vue'),
                meta: {
                    requiresAuth: true
                },
            },
            { // 试验数据处理之沥青设备处理--软化点
                path: '/softenPointProcess',
                name: 'softenPointProcess',
                component: () =>
                    import('../views/machineNetworkManage/testDataProcessManage/asphaltEquipmentProcess/penetrationProcess/index.vue'),
                meta: {
                    requiresAuth: true
                },
            },
            { // 试验数据处理之沥青设备处理--延度
                path: '/ductilityProcess',
                name: 'ductilityProcess',
                component: () =>
                    import('../views/machineNetworkManage/testDataProcessManage/asphaltEquipmentProcess/ductilityProcess/index.vue'),
                meta: {
                    requiresAuth: true
                },
            },
            { // 试验数据处理之沥青混合料处理--稳定度
                path: '/stabilityProcess',
                name: 'stabilityProcess',
                component: () =>
                    import('../views/machineNetworkManage/testDataProcessManage/asphaltMixtureProcess/stabilityProcess/index.vue'),
                meta: {
                    requiresAuth: true
                },
            },
            { // 试验数据处理之沥青混合料处理--沥青含量
                path: '/asphaltContentProcess',
                name: 'asphaltContentProcess',
                component: () =>
                    import('../views/machineNetworkManage/testDataProcessManage/asphaltMixtureProcess/asphaltContentProcess/index.vue'),
                meta: {
                    requiresAuth: true
                },
            },
            { // 试验数据处理之沥青混合料处理--车辙
                path: '/rutProcess',
                name: 'rutProcess',
                component: () =>
                    import('../views/machineNetworkManage/testDataProcessManage/asphaltMixtureProcess/rutProcess/index.vue'),
                meta: {
                    requiresAuth: true
                },
            },

            // 试验机联网

            // 待试验样品
            { //水泥
                path: '/cementTest',
                name: 'cementTest',
                component: () =>
                    import('../views/sampleTestManage/cementTest/index.vue'),
                meta: {
                    requiresAuth: true
                },
            },
            { //钢筋
                path: '/rebarTest',
                name: 'rebarTest',
                component: () =>
                    import('../views/sampleTestManage/rebarTest/index.vue'),
                meta: {
                    requiresAuth: true
                },
            },
            { //混凝土
                path: '/concreteTest',
                name: 'concreteTest',
                component: () =>
                    import('../views/sampleTestManage/concreteTest/index.vue'),
                meta: {
                    requiresAuth: true
                },
            },
            { //砂浆
                path: '/mortarTest',
                name: 'mortarTest',
                component: () =>
                    import('../views/sampleTestManage/mortarTest/index.vue'),
                meta: {
                    requiresAuth: true
                },
            },
            { //净浆
                path: '/pastTest',
                name: 'pastTest',
                component: () =>
                    import('../views/sampleTestManage/pastTest/index.vue'),
                meta: {
                    requiresAuth: true
                },
            },
            { //岩石
                path: '/rockTest',
                name: 'rockTest',
                component: () =>
                    import('../views/sampleTestManage/rockTest/index.vue'),
                meta: {
                    requiresAuth: true
                },
            },
            { //水稳
                path: '/waterStabilityTest',
                name: 'waterStabilityTest',
                component: () =>
                    import('../views/sampleTestManage/waterStabilityTest/index.vue'),
                meta: {
                    requiresAuth: true
                },
            },
            // 待试验样品

            // 试验数据监控
            { // 水泥
                path: '/cementMonitor',
                name: 'cementMonitor',
                component: () =>
                    import('../views/testMonitorManage/cementMonitor/index.vue'),
                meta: {
                    requiresAuth: true
                },
            },
            { // 钢筋
                path: '/rebarMonitor',
                name: 'rebarMonitor',
                component: () =>
                    import('../views/testMonitorManage/rebarMonitor/index.vue'),
                meta: {
                    requiresAuth: true
                },
            },
            { // 混凝土
                path: '/concreteMonitor',
                name: 'concreteMonitor',
                component: () =>
                    import('../views/testMonitorManage/concreteMonitor/index.vue'),
                meta: {
                    requiresAuth: true
                },
            },
            { // 砂浆
                path: '/mortarMonitor',
                name: 'mortarMonitor',
                component: () =>
                    import('../views/testMonitorManage/mortarMonitor/index.vue'),
                meta: {
                    requiresAuth: true
                },
            },
            { // 净浆
                path: '/pastMonitor',
                name: 'pastMonitor',
                component: () =>
                    import('../views/testMonitorManage/pastMonitor/index.vue'),
                meta: {
                    requiresAuth: true
                },
            },
            { // 岩石
                path: '/rockMonitor',
                name: 'rockMonitor',
                component: () =>
                    import('../views/testMonitorManage/rockMonitor/index.vue'),
                meta: {
                    requiresAuth: true
                },
            },
            { // 水稳
                path: '/waterStabilityMonitor',
                name: 'waterStabilityMonitor',
                component: () =>
                    import('../views/testMonitorManage/waterStabilityMonitor/index.vue'),
                meta: {
                    requiresAuth: true
                },
            },
            // 试验数据监控

            // 试验数据处理
            { // 水泥
                path: '/cementProcess',
                name: 'cementProcess',
                component: () =>
                    import('../views/testProcessManage/cementProcess/index.vue'),
                meta: {
                    requiresAuth: true
                },
            },
            { // 钢筋
                path: '/rebarProcess',
                name: 'rebarProcess',
                component: () =>
                    import('../views/testProcessManage/rebarProcess/index.vue'),
                meta: {
                    requiresAuth: true
                },
            },
            { // 混凝土
                path: '/concreteProcess',
                name: 'concreteProcess',
                component: () =>
                    import('../views/testProcessManage/concreteProcess/index.vue'),
                meta: {
                    requiresAuth: true
                },
            },
            { // 砂浆
                path: '/mortarProcess',
                name: 'mortarProcess',
                component: () =>
                    import('../views/testProcessManage/mortarProcess/index.vue'),
                meta: {
                    requiresAuth: true
                },
            },
            { // 净浆
                path: '/pastProcess',
                name: 'pastProcess',
                component: () =>
                    import('../views/testProcessManage/pastProcess/index.vue'),
                meta: {
                    requiresAuth: true
                },
            },
            { // 岩石
                path: '/rockProcess',
                name: 'rockProcess',
                component: () =>
                    import('../views/testProcessManage/rockProcess/index.vue'),
                meta: {
                    requiresAuth: true
                },
            },
            { // 水稳
                path: '/waterStabilityProcess',
                name: 'waterStabilityProcess',
                component: () =>
                    import('../views/testProcessManage/waterStabilityProcess/index.vue'),
                meta: {
                    requiresAuth: true
                },
            },
            // 试验数据处理

            // 数据统计分析
            { // 数据统计分析--混凝土质量趋势
                path: '/concreteQuality',
                name: 'concreteQuality',
                component: () =>
                    import('../views/dataStatisticalAnalysisManage/concreteQuality/index.vue'),
                meta: {
                    requiresAuth: true
                },
            },
            { // 数据统计分析--钢筋质量趋势
                path: '/rebarQuality',
                name: 'rebarQuality',
                component: () =>
                    import('../views/dataStatisticalAnalysisManage/rebarQuality/index.vue'),
                meta: {
                    requiresAuth: true
                },
            }, { // 数据统计分析--水泥质量趋势
                path: '/cementQuality',
                name: 'cementQuality',
                component: () =>
                    import('../views/dataStatisticalAnalysisManage/cementQuality/index.vue'),
                meta: {
                    requiresAuth: true
                },
            }, { // 数据统计分析--砂浆质量趋势
                path: '/mortarQuality',
                name: 'mortarQuality',
                component: () =>
                    import('../views/dataStatisticalAnalysisManage/mortarQuality/index.vue'),
                meta: {
                    requiresAuth: true
                },
            },
            { // 数据统计分析--净浆质量趋势
                path: '/pasteQuality',
                name: 'pasteQuality',
                component: () =>
                    import('../views/dataStatisticalAnalysisManage/pasteQuality/index.vue'),
                meta: {
                    requiresAuth: true
                },
            },
            // 数据统计分析










            //系统管理 组织机构
            {
                path: '/mechanism',
                name: 'mechanism',
                component: () =>
                    import('../views/SysManage/BaseManage/mechanism.vue')
            },
            {
                path: '/department',
                name: 'department',
                component: () =>
                    import('../views/SysManage/BaseManage/department.vue')
            },
            {
                path: '/postManagement',
                name: 'postManagement',
                component: () =>
                    import('../views/SysManage/BaseManage/postManagement.vue')
            },
            {
                path: '/roleManagement',
                name: 'roleManagement',
                component: () =>
                    import('../views/SysManage/BaseManage/roleManagement.vue')
            }, {
                path: '/user',
                name: 'user',
                component: () =>
                    import('../views/SysManage/BaseManage/user.vue')
            },

            // 数据字典主页面
            {
                path: '/dictionaryPage',
                name: 'DictionaryPage',
                component: () =>
                    import('../views/SysManage/dictionaryPage.vue')
            },
            // 系统功能
            {
                path: '/systemData',
                name: 'SystemData',
                component: () =>
                    import('../views/SysManage/systemData.vue')
            },


        ]
    }
]

const router = new VueRouter({
    // mode: 'history',
    // base: process.env.BASE_URL,
    routes
})

// var code = JSON.parse(sessionStorage.getItem("monitorBack-ModuleList"))
// 导航守卫
// 使用 router.beforeEach 注册一个全局前置守卫，判断用户是否登陆
router.beforeEach((to, from, next) => {
    //如果去往登录页则放行 
    if (to.path === '/') {
        next();
    } else if (to.path === '/loginfree') {
        next();
    } else if (to.path === '/loginHttps') {
        next();
    } else if (to.path === '/detailedClose') {
        next();
    } else if (to.path === '/unqualifiedReportSingleSign') {
        next();
    } else {
        // if (to.meta.requiresAuth == true) {
        //     if (JSON.parse(sessionStorage.getItem("monitorBack-userInfo")).enCode != "System") {
        //         if (code.some(item => item.fEncode.includes(to.name))) {
        //             next();
        //         } else {
        //             next({
        //                 path: '/'
        //             });
        //         }
        //     }
        // }
        // console.log(5555, localStorage.getItem('monitorBack-token'));
        // 从本地存储里获取token
        let token = window.sessionStorage.getItem('monitorBack-token');
        // 判断token是否为空如果为空则跳转到登录页 如果有则放行
        if (token === null || token === '') {
            next({
                path: '/'
            });
        } else {
            next();
        }



        let userInfo = sessionStorage.getItem('monitorBack-userInfo')
        if (userInfo === null || userInfo === '') {
            next({
                path: '/'
            });
        } else {
            next();
        }
    }



});

export default router